package lion.framework.core.web.anno;

import java.lang.annotation.Annotation;

import org.apache.commons.lang.StringUtils;

import lion.dev.lang.MapJ;
import lion.framework.core.anno.AnnoProcessor;
import lion.framework.core.anno.IAnnotationProcessor;
import lion.framework.core.web.path.PathNode;
import lion.framework.core.web.path.PathNodeMapping;
import lion.framework.core.web.path.PathVar;
import lion.framework.core.web.views.ResultType;

/**
 * 
 * 类上的Namespace注解，对于存在ref引用的，则增加一个PathNode,让其forward至ref的PathNode
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年11月13日
 */
@AnnoProcessor(Namespace.class)
public class NamespaceAnnoProcessor implements IAnnotationProcessor {

	@Override
	public void processe(MapJ ctx, Annotation anno) throws Exception {

		Namespace nsNamespace = (Namespace) anno;
		String path = nsNamespace.value();
		String ref = nsNamespace.ref();

		if (StringUtils.isBlank(ref) || StringUtils.isBlank(path)) { return; }

		path = PathVar.replacePathVars(path);
		ref = PathVar.replacePathVars(ref);

		PathNode node = PathNodeMapping.add(path);
		node.addView("success", ref, ResultType.FORWARD);
	}
}
